<template>
  <div id="app">
    <div id="nav">
      <button @click = 'handleAdd'>加</button>
      <button @click = 'handleSub'>减</button>
      <button @click = 'handleAsync'>异步</button>
      <div>{{counter}}</div>
      <!-- <div>{{isOddOrEven}}</div> -->
      <div>{{counter | isOddOrEven}}</div>
    </div>
  </div>
</template>
<script>
export default {
  // 计算属性
  // computed: {
  //   isOddOrEven: function () {
  //     return this.counter % 2 === 0 ? '偶数' : '奇数'
  //   }
  // },
  // 过滤器
  filters: {
    isOddOrEven: function (value) {
      return value % 2 === 0 ? '偶数' : '奇数'
    }
  },
  data: function () {
    return {
      counter: 888
    }
  },
  methods: {
    handleAdd: function () {
      this.counter++
    },
    handleSub: function () {
      this.counter--
    },
    handleAsync: function () {
      setTimeout(() => {
        this.counter++
      }, 2000)
    }
  }
}
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
